<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/27
 * Time: 11:15
 */

namespace App\HttpController\Home;

use App\Utility\Pool\MysqlObject;
use App\Utility\Pool\MysqlPool;

class System extends Base
{
    /**
     * 系统配置
     * @return bool|void
     * @throws \EasySwoole\Component\Pool\Exception\PoolEmpty
     * @throws \EasySwoole\Component\Pool\Exception\PoolException
     * @throws \Throwable
     */
    public function index()
    {
        $data = MysqlPool::invoke(function (MysqlObject $db){
            $systems = $db->where('`group`','basic')->get('siam_config');
            $data = [];
            foreach ($systems as $k=>$v){
                if( $v['name'] == 'qq_group_img' ){
                    $data['qq_group_img'] = $v['value'];
                }
                if( $v['name'] == 'qq_group_num' ){
                    $data['qq_group_num'] = $v['value'];
                }
                if( $v['name'] == 'wechat_group' ){
                    $data['wechat_group_img'] = $v['value'];
                }
                if( $v['name'] == 'login_url' ){
                    $data['login_url'] = $v['value'];
                }
                if( $v['name'] == '86cm' ){
                    $data['app_down'] = $v['value'];
                }
                if( $v['name'] == 'friend_url' ){
                    $values = json_decode($v['value'],true);
                    foreach ( $values as $k1=>$v1 ){
                        $data['friend_url'][] = ['title'=>$k1,'url'=>$v1];
                    }
                }
                if( $v['name'] == 'about' ){
                    $data['about'] = $v['value'];
                }
                if( $v['name'] == 'map' ){
                    $data['map'] = $v['value'];
                }
                if( $v['name'] == 'link' ){
                    $data['link'] = $v['value'];
                }
                if( $v['name'] == 'dayi' ){
                    $data['dayi'] = $v['value'];
                }
                if( $v['name'] == 'cooperation' ){
                    $data['cooperation'] = $v['value'];
                }
                if( $v['name'] == 'weibo' ){
                    $data['weibo'] = $v['value'];
                }
            }
            return $data;
        });
        $this->writeJson(1,$data,'请求成功');
    }

    public function notice()
    {
        $data = MysqlPool::invoke(function (MysqlObject $db){
            return $db->where('switch',1)->where('publishtime',time(),'<=')->get('siam_announcement',null,'id,content,title');
        });
        $this->writeJson(1,$data,'请求成功');
    }
}